const { shared } = wx.worklet
const GestureState = {
  POSSIBLE: 0,
  BEGIN: 1,
  ACTIVE: 2,
  END: 3,
  CANCELLED: 4
}

Page({
  data: {
    list: new Array(10).fill(1)
  },
  onLoad(options) {
    const scrollX = shared(0)
    const gestureX = shared(0)

    this.applyAnimatedStyle('.circle-scroll', () => {
      'worklet'

      return {
        transform: `translateX(${scrollX.value}px)`
      }
    })

    this.applyAnimatedStyle('.circle-gesture', () => {
      'worklet'
      return {
        transform: `translateX(${gestureX.value}px)`
      }
    })

    this.scrollX = scrollX
    this.gestureX = gestureX
  },
  shouldScrollViewResponse() {
    'worklet'
    console.log('shouldScrollViewResponse')
    return true
  },
  shouldScrollViewAccept() {
    'worklet'
    return true
  },
  adjustDecelerationVelocity(velocity) {
    'worklet'
    console.log('adjustDecelerationVelocity', velocity)
    return velocity
  },
  handleScroll(evt) {
    'worklet'
    console.log('handleScroll', evt)
    const scrollTop = evt.detail.scrollTop
    this.scrollX.value = scrollTop
  },
  handleGesture(evt) {
    'worklet'
    console.log(evt.deltaY)
    if (evt.state === GestureState.ACTIVE) {
      this.gestureX.value -= evt.deltaY
    }
  }
})
